#include <iostream>
#include "audio.h"
#include						<portaudio\portaudio.h>

Audio::Audio(QObject *parent) : QObject(parent)
{
//	_player.start();
//	_recorder.start();
	int err = Pa_Initialize();
	if(err != paNoError)
		Pa_GetErrorText(err);
	_encoder.start();
	_recorder.init();
	//_recorder.start();

	connect(&_recorder, SIGNAL(newBuffer(short *)), this, SLOT(handleNewBuffer(short*)));
}

Audio::~Audio()
{
	int err = Pa_Terminate();
	if( err != paNoError )
		Pa_GetErrorText(err);
}

apiAudio						*Audio::getApi()
{
	return (new apiAudio(this));
}

Recorder						&Audio::getRecorder()
{
	return _recorder;
}

void							Audio::handleNewBuffer(short * buff)
{
	SoundPacket					*soundPkg = _recorder.getSoundPacket();

	soundPkg->setData(buff);
	emit newSound(soundPkg);
}